package net.frankish.logging;

import java.util.ArrayList;
import java.util.Queue;
import java.util.logging.Handler;
import java.util.logging.LogRecord;

public class MemoryLogHandler extends Handler {

	private static ArrayList<LogRecord> list = new ArrayList<LogRecord>();
	private int maxCapacity = 0;
	public MemoryLogHandler(int memoryConsoleLimit) {
		super();
		maxCapacity = memoryConsoleLimit;
	}

	@Override
	public void close() throws SecurityException {
		list.clear();
	}

	@Override
	public void flush() {
		list.trimToSize();
	}

	@Override
	public void publish(LogRecord record) {
		if(list.size() == maxCapacity){
			list.remove(0);
		}
		list.add(record);
	}

	public static ArrayList<LogRecord> getLog(){
		return list;
	}
}
